package org.nokatag.accordion;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import org.nokatag.system.BugInfoWrint;
import org.nokatag.tagjava.NokaTag;

public class LeftMenuTag extends  NokaTag{
	private static final long serialVersionUID = 5190866783863389074L;
	
	private String id = null;//div id
	private String cent = null;//菜单
	private String open = "1";
	private Integer minwidth= 40;
	private Integer maxwidth= 180;
	private Integer sidebaLeft=8;
	private String style = null;//css文件地址
	private String keepstate = null;//
	private String modechange = null;//模式式改变调用的js方法
	private String sty = null;//
	
	private  JspWriter jspOut =null;
	
	public int doStartTag()throws JspException{
		try{
			jspOut= pageContext.getOut();
			HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
			StringBuilder body = new StringBuilder();
			body.append(potjs(request));//js框架
			body.append(leftMenuJS(request,style));//select js
			if(null==cent){
				body.append("<iframe id=\""+id+"_cent_body\" style=\"display:none;left:50px;float:left;top:50px;right:0px;bottom:0px;position: absolute;border: 0\"></iframe>");
			}
			body.append("<div id=\""+id+"_leftmenu_width\" style=\"display:none;left:0px;top:0px;width:100%;height:0px;background:red;border:0px;position: absolute;\"></div>");
			body.append("<div id=\""+id+"_leftmenu_height\" style=\"left:0px;top:0px;width:0px;height:100%;background:red;border:0px;position:absolute;z-index:99999;\"></div>");
			body.append("<div  id=\""+id+"\" style=\"float: left;\"></div>");
			body.append("<div  id=\""+id+"_rightsub\" style=\"float: left;display: none;\"></div>");
			body.append("<script type=\"text/javascript\">");
			//---------------显示树形菜单---------------------------
			body.append("Event.observe(document, 'dom:loaded', function() {");
			//--------------------------------------------------------------------
			body.append("var sfg"+id+" = {");
			body.append("id:'"+id+"',");//id
			if("true".equals(keepstate)){
				body.append("keepstate:true,");//
			}
			if(null!=modechange){
				body.append("modechange:"+modechange+",");//
			}
			if(null!=sty){
				body.append("sty:"+sty+",");//
			}
			body.append("cent:'"+(cent==null?id+"_cent_body":cent)+"',");
			body.append("open:'"+open+"',");
			body.append("minwidth:'"+minwidth+"',");
			body.append("maxwidth:'"+maxwidth+"',");
			body.append("sidebaLeft:'"+sidebaLeft+"',");
			body.append("menu:");
			jspOut.write(body.toString());
		}catch(Exception se){
			 BugInfoWrint.Print(se);
		}
		return EVAL_BODY_INCLUDE;
	}
	public int doEndTag() throws JspException {
		try {
			StringBuilder body = new StringBuilder();
			body.append("};");
			body.append("var nrcor"+id+" = new nokaaccordion(sfg"+id+");");
			body.append("nrcor"+id+".show();");
			body.append("});");
			body.append("</script>");
			//---------------显示树形菜单---------------------------
			pageContext.getOut().write(body.toString());
			} catch (IOException e) {
				e.printStackTrace();
			}
		return EVAL_PAGE;
	}
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getCent() {
		return cent;
	}
	public void setCent(String cent) {
		this.cent = cent;
	}
	public String getOpen() {
		return open;
	}
	public void setOpen(String open) {
		this.open = open;
	}
	public Integer getMinwidth() {
		return minwidth;
	}
	public void setMinwidth(Integer minwidth) {
		this.minwidth = minwidth;
	}
	public Integer getMaxwidth() {
		return maxwidth;
	}
	public void setMaxwidth(Integer maxwidth) {
		this.maxwidth = maxwidth;
	}
	public Integer getSidebaLeft() {
		return sidebaLeft;
	}
	public void setSidebaLeft(Integer sidebaLeft) {
		this.sidebaLeft = sidebaLeft;
	}
	public String getStyle() {
		return style;
	}
	public void setStyle(String style) {
		this.style = style;
	}
	public String getKeepstate() {
		return keepstate;
	}
	public void setKeepstate(String keepstate) {
		this.keepstate = keepstate;
	}
	public String getModechange() {
		return modechange;
	}
	public void setModechange(String modechange) {
		this.modechange = modechange;
	}
	public String getSty() {
		return sty;
	}
	public void setSty(String sty) {
		this.sty = sty;
	}
	
}
